package ch.kerbtier.malurus.models;

import java.util.ArrayList;
import java.util.List;

public class GenericModel<T> implements Model<T> {
	private T value;
	private List<ModelListener> listeners = new ArrayList<ModelListener>();

	public T getValue() {
		return value;
	}

	public void setValue(T value) {
		if (value == null && this.value != null || value != null && !value.equals(this.value)) {
			this.value = value;
			for (ModelListener<T> ml : listeners) {
				ml.valueChanged(this);
			}
		}
	}

	public void addListener(ModelListener<T> modelListener) {
		listeners.add(modelListener);
	}

	public void removeListener(ModelListener<T> modelListener) {
		listeners.remove(modelListener);
	}
}


